var n = getApp();

Page({
    data: {
        imageurl: "",
        ad: {},
        isGood:false,
        tuijiantype:''
    },
    hideGood(){
      this.setData({
        isGood:false
      })
    },
    onShow(){
        // this.getRandomAd()
        getApp().chaping()
    },
    onLoad: function(a) {
        // this.setData({
        //   tuijiantype:getApp().globalData.tuijiantype
        // })
        // getApp().getRandomAd(true,this)
        // this.getRandomAd(true)
        this.setData({
          gezi:getApp().globalData.gezi
        })
        this.setData({
          ad:getApp().globalData.selfAd.filter(item=>item.type=='banner')[0]
        })
        this.setData({
            imageurl: a.imageurl
        });
    },
    save: function() {
      let that = this
        wx.saveImageToPhotosAlbum({
            filePath: this.data.imageurl,
            success: function(n) {
              that.setData({
                isGood:true
              })
            },
            fail: function(n) {
                wx.showModal({
                    title: '提示',
                    content: '需要您授权保存相册',
                    showCancel: false,
                    success: modalSuccess => {
                      wx.openSetting({
                        success(settingdata) {
                          console.log("settingdata", settingdata)
                          if (settingdata.authSetting['scope.writePhotosAlbum']) {
                            wx.showModal({
                              title: '提示',
                              content: '获取权限成功,再次点击即可保存。',
                              showCancel: false,
                            })
                          } else {
                            wx.showModal({
                              title: '提示',
                              content: '获取权限失败，将无法保存到相册哦~',
                              showCancel: false,
                            })
                          }
                        },
                        fail(failData) {
                          console.log("failData", failData)
                        },
                        complete(finishData) {
                          console.log("finishData", finishData)
                        }
                      })
                    }
                })
            }
        });
    },
    previewImage: function(n) {
        var a = this, e = [];
        e.push(a.data.imageurl), wx.previewImage({
            current: e[0],
            urls: e
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
      return {
          title: "超好用的图片编辑小程序",
          path: "pages/index/index",
          imageUrl: "/image/maskshareimg.jpg"
      };
  },
});